/**
 * 通用类型定义
 * 减少any类型使用，提升类型安全性
 */

// 基础响应类型
export interface IBaseResponse<T = any> {
  code: number;
  msg: string;
  data: T;
}

// 分页参数类型
export interface IPaginationParams {
  pageNum: number;
  pageSize: number;
  [key: string]: any;
}

// 分页响应类型
export interface IPaginationResponse<T = any> {
  total: number;
  rows: T[];
  pageNum: number;
  pageSize: number;
}

// 菜单节点类型
export interface IMenuNode {
  id: string | number;
  title?: string;
  name?: string;
  path?: string;
  component?: string | (() => Promise<any>);
  meta?: {
    title?: string;
    icon?: string;
    hidden?: boolean;
    [key: string]: any;
  };
  children?: IMenuNode[];
  [key: string]: any;
}

// 用户信息类型
export interface IUserInfo {
  id: string;
  username: string;
  realName: string;
  email: string;
  mobile: string;
  headUrl?: string;
  gender: number;
  deptId: string;
  deptName: string;
  postIdList: string;
  roleIdList: string;
  status: number;
  superAdmin: number;
  createDate: string;
  [key: string]: any;
}

// 权限类型
export interface IPermission {
  id: string;
  name: string;
  code: string;
  type: number;
  [key: string]: any;
}

// 角色类型
export interface IRole {
  id: string;
  name: string;
  organizationType: number;
  authorityType: string;
  note?: string;
  menuIdList: (string | number)[];
  [key: string]: any;
}

// 组织类型
export interface IOrganizationType {
  id: string;
  type: string;
  authorityType: string;
  menuIdList: (string | number)[];
  [key: string]: any;
}

// 表单验证规则类型
export interface IFormRule {
  required?: boolean;
  message?: string;
  trigger?: string | string[];
  min?: number;
  max?: number;
  pattern?: RegExp;
  validator?: (rule: any, value: any, callback: any) => void;
  [key: string]: any;
}

// 表单验证规则集合类型
export interface IFormRules {
  [key: string]: IFormRule | IFormRule[];
}

// 树节点类型
export interface ITreeNode {
  id: string | number;
  label?: string;
  name?: string;
  children?: ITreeNode[];
  disabled?: boolean;
  [key: string]: any;
}

// 表格列类型
export interface ITableColumn {
  prop: string;
  label: string;
  width?: string | number;
  minWidth?: string | number;
  fixed?: boolean | 'left' | 'right';
  sortable?: boolean;
  [key: string]: any;
}

// 搜索条件类型
export interface ISearchCondition {
  field: string;
  operator: 'eq' | 'ne' | 'gt' | 'gte' | 'lt' | 'lte' | 'like' | 'in' | 'notIn';
  value: any;
  [key: string]: any;
}

// 排序条件类型
export interface ISortCondition {
  field: string;
  order: 'asc' | 'desc';
}

// 文件上传类型
export interface IFileInfo {
  name: string;
  size: number;
  type: string;
  url?: string;
  [key: string]: any;
}

// 字典项类型
export interface IDictItem {
  label: string;
  value: string | number;
  [key: string]: any;
}

// 字典类型
export interface IDictType {
  type: string;
  name: string;
  items: IDictItem[];
  [key: string]: any;
}

// 通用状态类型
export type StatusType = 0 | 1; // 0: 禁用, 1: 启用

// 通用性别类型
export type GenderType = 0 | 1 | 2; // 0: 未知, 1: 男, 2: 女

// 通用组织类型
export type OrganizationType = 1 | 2; // 1: Installer, 2: Distributor

// 通用权限类型
export type AuthorityType = 'Web' | 'App' | '0' | '1';

// 通用操作类型
export type OperationType = 'add' | 'edit' | 'delete' | 'view';

// 通用对话框类型
export type DialogType = 'add' | 'edit' | 'view';

// 通用抽屉类型
export type DrawerType = 'add' | 'edit' | 'view';

// 通用表格选择类型
export type SelectionType = 'single' | 'multiple';

// 通用加载状态类型
export type LoadingType = 'loading' | 'success' | 'error' | 'idle';
